package com.yili.oa.dao.extend;

import com.yili.oa.dao.FtAccountDetailsMapper;
import com.yili.oa.entity.FtAccountDetailsSearch;
import com.yili.oa.models.FtAccountDetails;
import com.yili.oa.vo.response.FtAccountDetailsRes;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.math.BigDecimal;
import java.util.List;

public interface FtAccountDetailsExtendMapper {

    @SelectProvider(type=FtAccountDetailsExtendSqlProvider.class, method="get")
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
            @Result(column="trade_time", property="tradeTimeStr", jdbcType=JdbcType.BIGINT),
            @Result(column="expense", property="expense", jdbcType=JdbcType.DECIMAL),
            @Result(column="income", property="income", jdbcType=JdbcType.DECIMAL),
            @Result(column="account_balance", property="accountBalance", jdbcType=JdbcType.DECIMAL),
            @Result(column="trade_type", property="tradeType", jdbcType=JdbcType.INTEGER),
            @Result(column="user_id", property="userId", jdbcType=JdbcType.BIGINT),
            @Result(column="tradeType", property="tradeTypeStr", jdbcType=JdbcType.VARCHAR)
    })
    List<FtAccountDetailsRes> get(FtAccountDetailsSearch searchBase);

    @SelectProvider(type=FtAccountDetailsExtendSqlProvider.class, method="getSum")
    BigDecimal getSum(@Param("direction") String direction,@Param("userId") Long userId,@Param("tradeTypes") List<Integer> tradeTypes);


    @Select(
        "select account_balance from ft_account_details where trade_time = (\n" +
                "select max(trade_time) as amount from ft_account_details where user_id=#{userId,jdbcType=BIGINT}) and user_id = #{userId,jdbcType=BIGINT}"
    )
    BigDecimal getAccountBlance(Long id);



}
